home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / dev / lang / J4thDemo.lha / Tutorials / Overview < prev    next >
Encoding:
Text File  |  1992-09-17  |  13.6 KB  |  316 lines

  1.  
  2.                      INTRODUCTION TO JFORTH
  3.     
  4.     (Note that features followed by (*) are not provided in the 
  5.     demo)
  6.     
  7.     JForth is a programming language that allows you to interact 
  8.     with your Amiga.  When you are programming in JForth, you 
  9.     are "inside" the language. You can access any data 
  10.     structure, test any routine, or use any development tool, 
  11.     right from the keyboard.  This direct communication with the 
  12.     computer can improve your productivity, giving you 
  13.     additional time to improve the quality of your software 
  14.     products.
  15.     
  16.     JForth is based on the 1983 standard Forth language.  Forth 
  17.     was first conceived by Charles Moore when he wanted a new 
  18.     language for controlling telescopes.  He developed a 
  19.     language based on a dictionary of words.  This dictionary 
  20.     can be extended by writing new words based on the old ones. 
  21.     Since Mr. Moore's original version, Forth has been 
  22.     translated to almost every type of computer from the biggest 
  23.     mainframes to the smallest microcomputers.
  24.     
  25.     Since a minimal Forth can be implemented in just a few 
  26.     kilobytes of memory, it is often used in very small embedded 
  27.     computer systems for process control and robotics.  Forth, 
  28.     however, is equally appropriate for larger, more advanced, 
  29.     computers like the Amiga.  Forth is a very flexible language 
  30.     and can be adapted to larger computers without losing the 
  31.     flavor of the original language. 
  32.     
  33.     JForth is an implementation of Forth designed specifically 
  34.     for the Commodore Amiga.  JForth uses a 32-bit stack and 
  35.     compiles directly to 68000 machine code.  This makes JForth 
  36.     faster than most Forths.  JForth also provides an extensive 
  37.     set of tools for accessing the special features of the 
  38.     Amiga.  You can call any Amiga Library routine by name (*) and 
  39.     reference any Amiga structure using constructs similar to 
  40.     'C'.  JForth also has some special toolboxes that support 
  41.     simple graphics, Intuition menus, IFF files, and other Amiga 
  42.     features.  These toolboxes can be used directly to simplify 
  43.     your Amiga programming.  In the product release, the source 
  44.     code for all these toolboxes is provided (*) so you can 
  45.     customize them if needed or study them as examples of Amiga 
  46.     programming.  JForth also provides over a dozen small sample 
  47.     programs for those, like me, who learn best by example.
  48.     (This demo includes a few of them).  
  49.     
  50.     JForth also allows you to do things that are unique in the 
  51.     Forth experience, the most dramatic being CLONE (*).  This 
  52.     exeptional utility allows you to create a totally 
  53.     independant, standalone version of your program of minimal 
  54.     size that is entirely royalty free! 
  55.     
  56.     
  57.                    MAJOR FUNCTIONAL SYSTEMS
  58.     
  59.     Amiga Library Calls
  60.     
  61.     JForth provides a system for easily calling any Amiga 
  62.     Library routine by name (*).  It will figure out what 68000 
  63.     registers the parameters go into and build the appropriate 
  64.     code.  Thus you can simply pass parameters on the stack in 
  65.     the order described in the Amiga documentation.  A number of 
  66.     toolboxes have been written for supporting specific parts of 
  67.     the Amiga Library including EZMENUS, Graphics, the Serial 
  68.     Device, ANSI codes, and much more.  In this demo, while you
  69.     can't create new calls to Amiga libraries, it DOES include
  70.     many in pre-compiled form.  To see a list, in JForth type:
  71.     
  72.        WORDS-LIKE ()
  73.     
  74.     Amiga Structure Support  
  75.     
  76.     JForth provides the equivalent to all of the ".h" include 
  77.     files from 'C' (*). These ".j" files define all of the 
  78.     necessary structures and constants for passing information 
  79.     to the Amiga Library routines.  Structures can be dumped 
  80.     interactively with all members shown by name and value for 
  81.     debugging by using DST.  Again, while the JForth include 
  82.     files are not provided with the demo, many structures exist 
  83.     in pre-compiled form.
  84.     
  85.     ARexx Support
  86.     
  87.     ARexx is a language that helps various applications 
  88.     communicate with each other.  A spread sheet program, for 
  89.     example, could communicate with a data base program.  These 
  90.     tools help you write ARexx compatible programs.  The demo 
  91.     JForth does include the AREXX interface and itself opens an 
  92.     AREXX port.  This port can be used to form an integrated 
  93.     text editor environment with Textra.
  94.     
  95.     Assembler
  96.     
  97.     JForth supports two 68000 assemblers, one with Reverse 
  98.     Polish Notation (RPN) and one with Motorola-like syntax.  
  99.     The RPN assembler can be used to create macros but the 
  100.     Motorola assembler is easier to read.  We also offer a 
  101.     Disassembler.
  102.     
  103.     Block Support and SCRED  (*)
  104.     
  105.     For those who prefer the old fashioned BLOCK or SCREEN 
  106.     environment, we provide LIST, LOAD and the standard line 
  107.     editor.  We also provide a WYSIWYG SCREEN editor called 
  108.     SCRED.  (We recommend the use of normal text files with 
  109.     JForth).
  110.     
  111.     Clone  (*)
  112.     
  113.     Clone can be used to generate small, royalty free, 
  114.     executable images of your JForth programs.  Clone will take 
  115.     a compiled JForth program, extract out all of the code and 
  116.     data needed to run it, and reassemble a smaller version of 
  117.     it.  All of the JForth development tools, the name fields 
  118.     and link fields and any other unused words are left behind.  
  119.     The final image size is comparable to images created using a 
  120.     'C' compiler and linker. Images can be saved with a symbol 
  121.     table for use with WACK or other debuggers (if needed).  The 
  122.     JForth Source Level Debugger can also be used with Cloned 
  123.     programs.  Most programs will Clone without modification if 
  124.     they follow a few simple rules regarding run time 
  125.     initialization of variables or arrays containing Forth 
  126.     addresses.
  127.     
  128.     Debugger
  129.     
  130.     JForth provides a source level debugger that allows you to 
  131.     single step through your code.  At every step you can see 
  132.     what is on the stack.  You can also examine the return 
  133.     stack, dump memory, set breakpoints, control execution, or 
  134.     even enter Forth commands.
  135.     
  136.     Floating Point  (*)
  137.     
  138.     JForth supports both the single precision Fast Floating 
  139.     Point and the IEEE double precision.  These words conform to 
  140.     the Forth Vendors Group Standard.
  141.     
  142.     IFF Support  
  143.     
  144.     JForth provides general purpose tools for reading and 
  145.     writing IFF files.  It also provides a toolbox specifically 
  146.     for ILBM graphics files.  This allows you to use pictures, 
  147.     brushes, anims and animbrushes from a paint program, or 
  148.     other source, in your programs.  JForth also provides tools 
  149.     for animation and presentation such as, blit, wipe, fade in, 
  150.     fade out, etc.  Powerful graphics and animation programs can 
  151.     be created using these tools.
  152.     
  153.     Local Variables  
  154.     
  155.     Local variables can simplify the definition of complex words 
  156.     by eliminating much of the stack manipulation.  Local 
  157.     variables are fast self fetching variables that allow 
  158.     reentrant recursive code to be written.  Using regular 
  159.     VARIABLEs can make a word non reentrant.
  160.     
  161.     Modules  (*)
  162.     
  163.     JForth's precompiled modules provide a method for rapidly 
  164.     accessing code that is used during compilation.  This 
  165.     includes the Assemblers and Disassembler, and the Amiga 
  166.     include files.  These modules are dynamically linked into 
  167.     the dictionary when needed.  This way, they do not take up 
  168.     space in your normal dictionary, yet are instantly 
  169.     available.
  170.     
  171.     MultiStandard  (*)
  172.     
  173.     This system allows you to switch easily between JForth and 
  174.     the major standards - FIG , '79 , and '83.  This is handy 
  175.     for compiling code written using other Forths.
  176.     
  177.     ODE  (*)
  178.     
  179.     ODE is an Object Oriented Development Environment similar in 
  180.     concept to SmallTalk.  It allows you to define classes of 
  181.     intelligent data structures, then create as many copies of 
  182.     these data structures as needed.  This technique can 
  183.     simplify programming immensely by making it easier to write 
  184.     reusable code.
  185.     
  186.     Profiler  (*)
  187.     
  188.     This optimization tool monitors the operation of a program 
  189.     to find out where it is spending its time.  Most programs 
  190.     spend most of their time in a small portion of the code By 
  191.     identifying this code, one can focus efforts at optimization 
  192.     where they are most needed.
  193.     
  194.     Textra
  195.     
  196.     Textra is a powerful, yet easy to use, multi-window text 
  197.     editor designed for programmers.  It uses the mouse to 
  198.     select text and allows Cut, Copy and Paste, operations 
  199.     between its windows.  It also incorporates ARexx hooks that 
  200.     allows you to use provided macros (.textra files) for text 
  201.     processing (or write your own).  Textra can communicate with 
  202.     JForth such that you can compile directly from the editor.  
  203.     If an error is encountered while compiling, Textra will 
  204.     highlight the error so the you can fix it quickly.  The 
  205.     documentation for Textra may be found in the JTX:DOCS 
  206.     directory.
  207.     
  208.     To access the '.textra' REXX scripts, they must reside 
  209.     in your 'rexx:' directory.  An ICONX-type script is 
  210.     provided to put them there with the click of a mouse.
  211.     (They will use about 25K of disk space).
  212.         
  213.     
  214.                JFORTH COMPARED TO OTHER FORTHS
  215.     
  216.     This section describes some of the ways in which JForth 
  217.     differs from other Forths.
  218.     
  219.     32 Bit Stack
  220.     
  221.     Forth uses what is called a "data stack" for passing values 
  222.     between words. It is a place to put numbers, addresses or 
  223.     other values.  Values can be added to the stack and removed 
  224.     just like on a stack of plates.  Most Forth implementations 
  225.     use a 16 bit stack.  This means that the numeric range in a 
  226.     standard Forth is -32,768 to 32,767.  JForth and a few other 
  227.     Forths, use a 32 bit stack which gives you a numeric range 
  228.     of -2,147,483,648 to 2,147,483,647.  Since JForth addresses 
  229.     are also 32 bit, you can address a much larger memory space 
  230.     than a 16 bit Forth.
  231.     
  232.     Jump Subroutine Threading
  233.     
  234.     Another major difference between JForth and most other 
  235.     Forths is that JForth is a true compiler.  In most 
  236.     Forths,when you "compile" a word, you actually end up 
  237.     creating a table of tokens or pointers to the other words 
  238.     that are called.  If your word calls '+' it will put a 
  239.     pointer to the plus function in your word.  When you execute 
  240.     your word, a program called the inner interpreter examines 
  241.     these pointers and then executes the appropriate functions 
  242.     That is the traditional method.
  243.     
  244.     In JForth we use what is called Jump Subroutine, or JSR, 
  245.     Threading.  That is where the 'J' in JForth comes from.  In 
  246.     JSR threading, actual 68000 machine code is compiled into 
  247.     your word.  If you call a word, JForth will compile a 68000 
  248.     JSR instruction to make that call.  This eliminates the need 
  249.     for an inner interpreter.  If the subroutine is small 
  250.     enough, JForth will copy the called routine inline into your 
  251.     routine thus avoiding the small overhead of the JSR 
  252.     instruction.  Since the 68000 executes code directly, JForth 
  253.     will run 2-3 times faster than a traditional Forth on the 
  254.     same machine.
  255.     
  256.     Relative Addressing
  257.     
  258.     In JForth, addresses are expressed as offsets relative to 
  259.     the base of the JForth image in memory.  This is important 
  260.     because AmigaDOS will load JForth at different places in 
  261.     memory at different times.  Despite this, your programs can 
  262.     use the same relative addresses at different times.  This 
  263.     can simplify Forth programming because variables, CFAs, 
  264.     dictionary links, and other addresses keep the same relative 
  265.     addresses even thought their absolute addresses may change.
  266.     
  267.     Amiga Libraries uses absolute addresses.  You will, 
  268.     therefore,  have to convert relative addresses to absolute 
  269.     before passing them to the Amiga.  This is a simple 
  270.     operation.  On the whole, we feel using relative addressing 
  271.     is an advantage over absolute addressing.  Here are the 
  272.     words used to convert addresses:
  273.     
  274.         >REL  ( absolute-address -- relative-address , convert )  
  275.         >ABS  ( relative-address -- absolute-address , convert )
  276.         
  277.     (Also remember that the addresses on the return stack will 
  278.     be absolute as well.)
  279.     
  280.     Text File Input  
  281.     
  282.     JForth will compile programs from "normal" ASCII text files 
  283.     created using standard Amiga text editors.  Thus you can use 
  284.     you favorite editor with JForth instead of the TEXTRA editor 
  285.     provided.  (Traditional Forths use a system of 1024 byte 
  286.     source code blocks. We provide support for this system for 
  287.     those who want it. (*))  
  288.     
  289.     NOT versus 0=  
  290.     
  291.     In the Forth '83 standard, NOT performs a 1's complement 
  292.     operation.  Since NOT is usually used for negating a logical 
  293.     value, this can sometimes give surprising results.  In 
  294.     Forth, any non zero value will be considered true by IF and 
  295.     other conditional words.  The traditional NOT only works 
  296.     with a true value of -1.  For that reason, JForth defines 
  297.     NOT as 0= which negates any true value.  In Forth '83:
  298.     
  299.         -1 NOT ( is false ) 
  300.         1 NOT ( is true!!, = -2 ) 
  301.         1 0=  ( is false ) 
  302.     
  303.     In JForth:
  304.     
  305.         -1 NOT ( is false ) 
  306.         1 NOT ( is false ) 
  307.         1 0=  ( is false )
  308.         
  309.     The JForth word COMP will perform a 1's complement operation 
  310.     like the '83 NOT.  If you want the traditional NOT you can 
  311.     redefine it or use the Multistandard package which gives you 
  312.     strict conformance with '83, FIG or '79 standards.
  313.     
  314.     If you have not already done so, please refer to the Tutorial
  315.     while following it in JForth.
  316.